﻿using System;
using System.Threading;
using HDM.NexusEngine.Graphics;
using SlimDX;
using SlimDX.DXGI;

namespace HDM.NexusEngine.Core
{
    public class RenderManager : IDisposable
    {
        private Thread _renderThread;
        private readonly GraphicsDeviceManager _deviceManager;

        public RenderManager(GraphicsDeviceManager graphicsDevice)
        {
            _deviceManager = graphicsDevice;
        }

        public void Init()
        {
            _renderThread = new Thread(Render);
            _renderThread.Start();
        }

        private void Render()
        {
            while (true)
            {
                _deviceManager.Context.ClearRenderTargetView(_deviceManager.RenderTarget, new Color4(0.25f, 0.75f, 0.25f));
                _deviceManager.SwapChain.Present(0, PresentFlags.None);
            }
        }

        public void Dispose()
        {
            _renderThread.Abort();
        }
    }
}